<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>课程定单</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" >
    <script th:src="@{/layui/layui.js}" charset="utf-8"></script>

</head>
<body>
<script>
//一般直接写在一个js文件中
//    layui.use(['layer', 'form'], function(){
//        var layer = layui.layer
//            ,form = layui.form;
//
//        layer.msg('Hello World');
//    });


</script>
<!--查询form-->
<span style="font-size: large">查询：</span>
<form class="layui-form" action="" id="searchform">
    <div class="layui-form-item">
        <label class="layui-form-label">WeChat号</label>
        <div class="layui-input-inline">
            <input type="text" name="wechat_no" id="wechat_no" placeholder="请输入WeChat号" autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label">WeChat备注</label>
        <div class="layui-input-inline">
            <input type="text" name="wechat_mark"  id='wechat_mark' placeholder="请输入WeChat备注" autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label">QQ</label>
        <div class="layui-input-inline">
            <input type="text" name="qq_no" id='qq_no' placeholder="请输入qq" autocomplete="off" class="layui-input">
        </div>

        <div class="site-demo-button" id="top_options" style="margin-bottom: 0;margin-right: 20px" align="right" >
            <!--<button data-method="selected-all" class="layui-btn layui-btn-sm">全选</button>-->
            <button class="layui-btn" layui-btn type="button" onclick="doSearch();">Search</button>
            <button type="reset" class="layui-btn layui-btn-primary">Rest</button>
            <button data-method="add" class="layui-btn">Add</button>
            <!--<button data-method="delete" class="layui-btn layui-btn-sm">删除</button>-->
        </div>
    </div>
</form>
<section class="larry-wrapper">

<!--<div class="site-demo-button" id="top_options" style="margin-bottom: 0;" >-->
    <!--<button data-method="selected-all" class="layui-btn layui-btn-sm">全选</button>-->
    <!--<button data-method="add" class="layui-btn layui-btn-sm">添加</button>-->
    <!--<button data-method="delete" class="layui-btn layui-btn-sm">删除</button>-->
<!--</div>-->
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="row_bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script th:inline="none">
    //加载layer模块
    var $,layer,table;
    layui.use('layer',function () {
        $ = layui.jquery;
        layer = layui.layer; //独立版的layer无需执行这一句
        //按钮的触发事件
        var active = {
            add:function () {
                parent.layer.open({
                    type:2,//2跳转到页面
                    offset: 'auto',
                    title:'添加课程订单',
                    content:'/courseorder/add',
                    area: ['1000px', '600px'],
                    btn:'关闭全部',
                    btnAlign:'c',
                    yes:function () {
                        parent.layer.closeAll();
                    }
                });
            }
        };

        $('#top_options .layui-btn').on('click', function(){
            var othis = $(this);
            var method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });
    });


   layui.use('table', function(){
        table = layui.table;

        table.render({
            elem: '#test'
            ,url:'/courseorder/list'
            ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            ,cols: [[
                {field:'uuid', width:120, title: '订单编号', sort: true}
                ,{field:'name', width:80, title: '姓名'}
                //,{field:'qq_no', width:80, title: 'QQ号'}
                ,{field:'wechat_no', width:180, title: '微信号'}
                ,{field:'wechat_mark', width:210, title: '微信备注'}
                ,{field:'course_name', width:180, title: '购买名称'}
                ,{field:'course_price', width:80, title: '价格'}
                ,{field:'order_date', width:160, title: '订单日期'}
                ,{fixed: 'right', width: 165, align:'center', toolbar: '#row_bar',title:'操作'}
            ]],
            page: true,
            limit:8,
            limits:[8,9],
            id:'testReload'
        });

       //监听行工具事件
       table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
           var data = obj.data //获得当前行数据
               ,layEvent = obj.event; //获得 lay-event 对应的值
           if(layEvent === 'detail'){
               doDetail(obj)
           } else if(layEvent === 'del'){
               layer.confirm('真的删除行么', function(index){
                   //obj.del(); //删除对应行（tr）的DOM结构
                   layer.close(index);
                   //向服务端发送删除指令
                   doDelete(obj);
               });
           } else if(layEvent === 'edit'){
               //layer.msg('编辑操作');
               doEdit(obj);
           }
       });

       function doEdit(obj) {
           var oId = obj.data.order_id;
           var url = '/courseorder/edit?order_id=' + oId;
           parent.layer.open({
               type:2,//2跳转到页面
               offset: 'auto',
               title:'修改定单',
               content:url,
               area: ['1000px', '600px'],
               btn:'关闭全部',
               btnAlign:'c',
               yes:function () {
                   parent.layer.closeAll();
               }
           });
       }


       function doDetail(obj) {
            var oId = obj.data.order_id;
            var url = '/courseorder/detail?order_id=' + oId;
            parent.layer.open({
                type:2,//2跳转到页面
                offset: 'auto',
                title:'详情',
                content:url,
                area: ['1000px', '450px'],
                btn:'关闭全部',
                btnAlign:'c',
                yes:function () {
                    parent.layer.closeAll();
                }
            });
        }

       function doDelete(obj) {

            var oId = obj.data.order_id;
           $.get('/courseorder/delete',{order_id:oId},function (resp) {
               console.log(resp);
               if(resp.success){
                   layer.msg("删除成功");
               }else{
                   layer.msg("删除失败" + resp.message);
               }
           });
       }


    });

    function doSearch() {
        //alert("xx");
        var wechat_no = $.trim($("#wechat_no").val());
        var wechat_mark = $.trim($('#wechat_mark').val());
        var qq_no = $.trim($('#qq_no').val());
        table.reload('testReload',{
            where:{
                wechat_no:wechat_no,
                wechat_mark:wechat_mark,
                qq_no:qq_no
            }
        });
    }
</script>
</section>
</body>
</html>
